<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="数据日期" prop="sjrq">
        <el-date-picker
          v-model="queryParams.sjrq"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="date"
          range-separator="-"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['buss:wgsqlsb:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="wgsqlsbList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="数据日期" width="100" align="center" prop="sjrq"  />
      <el-table-column label="机构" align="center" prop="orgName"/>
      <el-table-column label="管户经理" align="center" prop="userName"/>
      <el-table-column label="社区" width="120" align="center" prop="sssq"  />
      <el-table-column label="户数" align="center" prop="hs"  />
      <el-table-column label="总人数" align="center" prop="zrs"  />
      <el-table-column label="存款金额" width="100" align="center" prop="ckye"  />
      <el-table-column label="存款户数" align="center" prop="ckhs"  />
      <el-table-column label="人均存款金额" align="center" prop="rjckje"  />
      <el-table-column label="有效存款户数" align="center" prop="yxckhs"  />
      <el-table-column label="贷款余额" width="100" align="center" prop="dkye"  />
      <el-table-column label="贷款户数" align="center" prop="dkhs"  />
      <el-table-column label="人均贷款余额" width="100" align="center" prop="rjdkye"  />
      <el-table-column label="授信签约户数" align="center" prop="sxqyhs"  />
      <el-table-column label="授信签约率" align="center" prop="sxqyl"  />
      <el-table-column label="用信签约率" align="center" prop="yxqyl"  />
      <el-table-column label="电子银行个数" align="center" prop="dzyhgs"  />
      <el-table-column label="人均电子银行个数" align="center" prop="rjdzyhgs"  />
      <el-table-column label="活跃电子银行个数" align="center" prop="hydzyhgs"  />
      <el-table-column label="人均活跃电子银行个数" align="center" prop="rjhydzyhgs"  />
      <el-table-column label="产品户数" align="center" prop="productHs"  />
      <el-table-column label="有效产品户数" align="center" prop="vaildHs"  />
      <el-table-column label="产品户数(用于计算产品覆盖面)" align="center" prop="productCoverageHs"  />
      <el-table-column label="产品覆盖面" align="center" prop="productCoverage"  />
      <el-table-column label="有效产品(用于计算有效产品覆盖面)" align="center" prop="vaildCoverageHs"  />
      <el-table-column label="有效产品覆盖面" align="center" prop="vaildCoverage"  />
      <el-table-column label="18岁以下" align="center" prop="agez"  />
      <el-table-column label="大于等于18 小于25" align="center" prop="ageone"  />
      <el-table-column label="大于等于25 小于35" align="center" prop="agetwo"  />
      <el-table-column label="大于等于35小于55" align="center" prop="agethree"  />
      <el-table-column label="大于等于55 小于65" align="center" prop="agefour"  />
      <el-table-column label="大于等于65" align="center" prop="agefive"  />
      <el-table-column label="一星客户数" align="center" prop="firstlevel"  />
      <el-table-column label="二星客户数" align="center" prop="seclevel"  />
      <el-table-column label="三星客户数" align="center" prop="thrlevel"  />
      <el-table-column label="四星客户数" align="center" prop="fourlevel"  />
      <el-table-column label="五星客户数" align="center" prop="fivelevel"  />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改网格社区报表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWgsqlsb, getWgsqlsb, delWgsqlsb, addWgsqlsb, updateWgsqlsb } from "@/api/buss/bi/wgsqlsb";

export default {
  name: "Wgsqlsb",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 网格社区报表表格数据
      wgsqlsbList: [],
      orgIdOptions: [],
      userIdOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sssq: null,
        hs: null,
        zrs: null,
        ckye: null,
        ckhs: null,
        rjckje: null,
        yxckhs: null,
        dkye: null,
        dkhs: null,
        rjdkye: null,
        sxqyhs: null,
        sxqyl: null,
        yxqyl: null,
        dzyhgs: null,
        rjdzyhgs: null,
        hydzyhgs: null,
        rjhydzyhgs: null,
        productHs: null,
        vaildHs: null,
        productCoverageHs: null,
        productCoverage: null,
        vaildCoverageHs: null,
        vaildCoverage: null,
        agez: null,
        ageone: null,
        agetwo: null,
        agethree: null,
        agefour: null,
        agefive: null,
        firstlevel: null,
        seclevel: null,
        thrlevel: null,
        fourlevel: null,
        fivelevel: null,
        orgId: null,
        managerId: null,
        sjrq: null,
        createTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询网格社区报表列表 */
    getList() {
      this.loading = true;
      listWgsqlsb(this.queryParams).then(response => {
        this.wgsqlsbList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        sssq: null,
        hs: null,
        zrs: null,
        ckye: null,
        ckhs: null,
        rjckje: null,
        yxckhs: null,
        dkye: null,
        dkhs: null,
        rjdkye: null,
        sxqyhs: null,
        sxqyl: null,
        yxqyl: null,
        dzyhgs: null,
        rjdzyhgs: null,
        hydzyhgs: null,
        rjhydzyhgs: null,
        productHs: null,
        vaildHs: null,
        productCoverageHs: null,
        productCoverage: null,
        vaildCoverageHs: null,
        vaildCoverage: null,
        agez: null,
        ageone: null,
        agetwo: null,
        agethree: null,
        agefour: null,
        agefive: null,
        firstlevel: null,
        seclevel: null,
        thrlevel: null,
        fourlevel: null,
        fivelevel: null,
        orgId: null,
        managerId: null,
        sjrq: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sssq)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加网格社区报表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const sssq = row.sssq || this.ids
      getWgsqlsb(sssq).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改网格社区报表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.sssq != null) {
            updateWgsqlsb(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWgsqlsb(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const sssqs = row.sssq || this.ids;
      this.$confirm('是否确认删除网格社区报表编号为"' + sssqs + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delWgsqlsb(sssqs);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    orgIdFormat(row, column) {
      return this.selectDictLabel(this.orgIdOptions, row.orgId);
    },
    userIdFormat(row, column) {
      return this.selectDictLabel(this.userIdOptions, row.userId);
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('buss/reportLsb/exportWgsqywjdbService', {
        ...this.queryParams
      }, `网格社区报表.xlsx`)
    }
  }
};
</script>
